JBoss Community Archive (Read Only)

PicketLink

PicketLink IDM - Attribute Management

Each of the Identity Objects (User, Role,Group) have attributes associated with them.  In this page, we look at the api used in dealing with the attributes.

Attribute

An Attribute construction takes in a String key and a Value.  The value must be a Serializable type.

Examples

User Attributes

User user = new SimpleUser(userName);
user.setEmail(request.getEmail());
user.setFirstName(request.getFirstName());
user.setLastName(request.getLastName());

user.setAttribute( new Attribute<String>("address", request.getAddress()) );
user.setAttribute( new Attribute<String>("city", request.getCity()) );
user.setAttribute( new Attribute<String>("state", request.getState()) );
user.setAttribute( new Attribute<String>("postalCode", request.getPostalCode()) );
user.setAttribute( new Attribute<String>("country", request.getCountry()) );

We can have similar attributes on Role, Group etc.

Agent Attributes

An Agent is almost equivalent to the notion of an Application.

Agent agent = new SimpleAgent("My Application");
agent.setAttribute(new Attribute<String>("clientID", "xyz-abc"));

Attribute Values

Since an attribute value can take in a Serializable type, you can either have a single value or multiple values.

Single Valued Attribute

User storedUserInstance = identityManager.getUser("admin");

storedUserInstance.setAttribute(new Attribute<String>("one-valued", "1"));

identityManager.update(storedUserInstance);

User updatedUserInstance = identityManager.getUser(storedUserInstance.getId());

Attribute<String> oneValuedAttribute = updatedUserInstance.getAttribute("one-valued");

assertNotNull(oneValuedAttribute);
assertEquals("1", oneValuedAttribute.getValue());

//ROLES
Role storedRoleInstance = identityManager.getRole("Administrator");

storedRoleInstance.setAttribute(new Attribute<String>("one-valued", "1"));

identityManager.update(storedRoleInstance);

//GROUPS
Group storedGroupInstance = identityManager.getGroup("Test Group");

storedGroupInstance.setAttribute(new Attribute<String>("one-valued", "1"));

identityManager.update(storedGroupInstance);

Multi Valued Attribute

//USERS
User storedUserInstance = identityManager.getUser("admin");

storedUserInstance.setAttribute(new Attribute<String[]>("multi-valued", new String[] { "1", "2", "3" }));

identityManager.update(storedUserInstance);

User updatedUserInstance = identityManager.getUser(storedUserInstance.getId());

Attribute<String[]> multiValuedAttribute = updatedUserInstance.getAttribute("multi-valued");

assertNotNull(multiValuedAttribute);
assertEquals("1", multiValuedAttribute.getValue()[0]);
assertEquals("2", multiValuedAttribute.getValue()[1]);
assertEquals("3", multiValuedAttribute.getValue()[2]);


//ROLES
Role storedRoleInstance = identityManager.getRole("Administrator");

storedRoleInstance.setAttribute(new Attribute<String[]>("multi-valued", new String[] {"1", "2", "3"}));


identityManager.update(storedRoleInstance);

//GROUPS
Group storedGroupInstance = identityManager.getGroup("Test Group");

storedGroupInstance.setAttribute(new Attribute<String[]>("multi-valued", new String[] {"1", "2", "3"}));



identityManager.update(storedGroupInstance);
JBoss.org Content Archive (Read Only), exported from JBoss Community Documentation Editor at 2020-03-11 12:19:14 UTC, last content change 2013-01-16 18:46:05 UTC.